{{ $cfg := (site.Params.search) }}

{{ if ($cfg.internal.enabled) }}
    {{ $pages := (where (site.RegularPages) "Section" "in" ($cfg.internal.sections)) }}
    {{ $data := (newScratch) }}

    {{ ($data.Add "pages" slice) }}

    {{ range ($pages) }}

        {{ $tags := (newScratch) }}{{ ($tags.Add "tags" slice) }}
        {{ range (.GetTerms "tags") }}{{ ($tags.Add "tags" (.Title)) }}{{ end }}
        {{ $categories := (newScratch) }}{{ ($categories.Add "categories" slice) }}
        {{ range (.GetTerms "categories") }}{{ ($categories.Add "categories" (.Title)) }}{{ end }}

        {{ ($data.Add "pages" (dict
        "title" (.Title)
        "tags" ($tags.Get "tags")
        "categories" ($categories.Get "categories")
        "section" (.Section)
        "url" (.Permalink)
        "date" (.Date.UTC.Format "2006-01-02T15:04:05Z07:00")
        )) }}

    {{ end }}

    {{ $search := (($data.Get "pages") | uniq) }}

    {{ (($search) | jsonify) }}
{{ end }}
